#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define M_MAX 100000

struct vertex {
	int id;
	int degree;
};

/*
 * Global variables
 */
static vertex	V[M_MAX];
static int	vertex_count;


/*
 * wtf
int
get_idx_silly(int what)
{
	register int i = 0;

	while (what >= V[i].id && i < vertex_count)
		i++;

	return what == V[i].id ? i : i - 1;
}
*/

int
get_idx(int what, vertex *array, int a_size)
{
	int L = 0,
	    R = a_size - 1,
	    M = 0;

	while (L <= R) {
		M = (L + R) / 2;
		if (what > array[M].id)
			L = M + 1;
		else if (what < array[M].id)
			R = M - 1;
		else
			return M;
	}

	return L;
}

void
inc_degree(vertex *v, int id)
{
	register int i;
	int idx;

	idx = get_idx_silly(id);
	if (v[idx].id != id) {
		vertex_count++;
		for (i = idx; i < vertex_count; i++)
			v[i+1] = v[i];
		v[idx].id = id;
		v[idx].degree = 1;
	} else
		v[idx].degree++;
}

int
main(void)
{
	static char line[512];
	int	m;
	int	a, b = 0;
	register int i = 0;

	(void) freopen("degree.in", "r", stdin);
	(void) freopen("degree.out", "w", stdout);

	(void) fgets(line, sizeof line / sizeof line[0], stdin);
	(void) sscanf(line, "%d", &m);

	while (i < m) {
		(void) fgets(line, 512, stdin);
		(void) sscanf(line, "%d%d", &a, &b);
		a--; b--;
		inc_degree(V, a);
		inc_degree(V, b);
		i++;
	}

	printf("%d\n", vertex_count);
	for (i = 0; i < vertex_count; i++)
		printf("%d %d\n", V[i].id + 1, V[i].degree);

	return 0;
}
